package com.jvm123.blog.service

import com.jvm123.blog.dao.ApiRepos
import com.jvm123.blog.entity.Api
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class ApiService {

    @Autowired
    ApiRepos apiRepos

    boolean update(Api apiEntity) {
        println apiEntity
        Long id = apiEntity.getId()
        if (id == null || id <= 0) {
            apiEntity.setCreateDate(new Date())
            apiRepos.save(apiEntity)
        } else {
            Api api = apiRepos.findOne(id)
            api.setTitle(apiEntity.getTitle())
            api.setContent(apiEntity.getContent())
            api.setAuthor(apiEntity.getAuthor())
            api.setExampleUrl(apiEntity.getExampleUrl())
            api.setDocsUrl(api.getDocsUrl())
            apiRepos.save(api)
        }
        true
    }
}
